package com.pachong.android.baseuicomponent.activity;


import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;

import com.pachong.android.baseuicomponent.CompState;
import com.pachong.android.baseuicomponent.ILoadable;
import com.pachong.android.baseuicomponent.LoadState;
import com.pachong.android.baseuicomponent.NetUtils;
import com.pachong.android.baseuicomponent.R;
import com.pachong.android.baseuicomponent.view.BottomLoadStateView;


/**
 * 带有加载状态UI切换的Activity
 */
public abstract class LoadableActivity extends BaseActivity implements ILoadable {

    @Override
    public void startLoading() {
        if (NetUtils.getNetworkStatus(this) == NetUtils.NETWORK_STATE_IDLE) {
            setState(CompState.EMPTY_INVALID_NEWWORK);
            return;
        }
        setState(CompState.EMPTY_REFRESHING);
        onStartLoading();

    }


    @Override
    public void setAutoLoading(boolean auto) {

    }

    @Override
    public void setTriggerLoadItemCount(int itemCount) {

    }

    @Override
    public BottomLoadStateView createBottomLoadStateView(LayoutInflater inflater) {
        return null;
    }


    @Override
    public void changeLoadState(LoadState loadState) {

    }


    @Override
    public View createEmptyInvalidNetView(LayoutInflater inflater) {
        View view = inflater.inflate(R.layout.empty_invalid_net, null, false);
        view.findViewById(R.id.btnReload).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e("createEmptyInva","createEmptyInvalidNetView :"+"进来");
                startLoading();
            }
        });
        return view;
    }

    @Override
    public View createEmptyErrorView(LayoutInflater inflater) {
        View view = inflater.inflate(R.layout.empty_invalid_data, null, false);
        view.findViewById(R.id.btnReload).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e("createEmptyInva11","createEmptyInvalidNetView :"+"进来");
                startLoading();
            }
        });
        return view;
    }


}
